/*
 * @Descripttion: 意向客户跟进
 * @version:
 * @Author: lehaixia
 * @Date: 2023-05-03 13:33:31
 * @LastEditors: lehaixia
 * @LastEditTime: 2023-05-08 14:30:23
 */
import request from '@/plugins/request'
import { IResponseData } from '@/types/request-base'
import { json2FormData } from '@/utils'

/**
 * 意向客户跟进查询
 * @param {object} data 参数
 */
export function geList({ page, rows, sort, order, filtersRaw, sortersRaw, paramsRaw }: any) {
  const params = {
    page,
    rows,
    sort: sort || 'joinStatus',
    order: order || 'asc',
    pageFlag: true,
    onlyCountFlag: false,
    filtersRaw: JSON.stringify(filtersRaw),
    sortersRaw: JSON.stringify(sortersRaw),
    paramsRaw: JSON.stringify(paramsRaw)
  }
  const data = json2FormData(params)
  return request<IResponseData>({
    url: '/app/v1/ctmIntendedCustomerFollowUp/page',
    method: 'post',
    data
  })
}

/**
 *  编辑
 * @param data any
 * @param isHandover boolean 是否交接
 * @returns
 */
export function saveItem(data: any, isHandover = false) {
  return request<IResponseData>({
    url: isHandover ? '/app/v1/ctmIntendedCustomerFollowUp/submit' : '/app/v1/ctmIntendedCustomerFollowUp',
    method: 'put',
    data
  })
}

/**
 * 详情 根据ID查询
 * @param {string} ID
 */
export function detailItem(id: string) {
  return request<IResponseData>({
    method: 'get',
    url: `/app/v1/ctmIntendedCustomerFollowUp/getDataByIntendedCustomerId/${id}`,
    loading: true
  })
}
/**
 *  终止
 * @param data any
 * @returns
 */
export function terminateItem(data: any) {
  return request<IResponseData>({
    url: '/app/v1/ctmIntendedCustomerFollowUp/terminate',
    method: 'put',
    data
  })
}

/**
 *  提交
 * @param data any
 * @returns
 */
export function submitItem(data: any) {
  return request<IResponseData>({
    url: '/app/v1/ctmIntendedCustomerFollowUp/submit',
    method: 'put',
    data
  })
}

/**
 * 详情 根据id查询编辑页信息
 * @param {string} ID
 * @param isHandover boolean 是否交接
 */
export function editDetailItem(id: string, isHandover = false) {
  return request<IResponseData>({
    method: 'get',
    url: isHandover
      ? `/app/v1/ctmIntendedCustomerFollowUp/getDataAppSubmitByIntendedCustomerId/${id}`
      : `/app/v1/ctmIntendedCustomerFollowUp/getDataAppEditByIntendedCustomerId/${id}`,
    loading: true
  })
}

/**
 * 详情 根据id查询提交页信息
 * @param {string} ID
 */
export function submitDetailItem(id: string) {
  return request<IResponseData>({
    method: 'get',
    url: `/app/v1/ctmIntendedCustomerFollowUp/getDataAppSubmitByIntendedCustomerId/${id}`
  })
}

/**
 * 查询未被引用的市场数据查询
 * @param {object} data 参数
 */
export function getMarketList({ page, rows, sort, order, filtersRaw, sortersRaw, paramsRaw }: any) {
  const params = {
    page,
    rows,
    // sort: sort || 'lastUpdateTime',
    order: order || 'desc',
    pageFlag: true,
    onlyCountFlag: false,
    filtersRaw: JSON.stringify(filtersRaw),
    sortersRaw: JSON.stringify(sortersRaw),
    paramsRaw: JSON.stringify(paramsRaw)
  }
  const data = json2FormData(params)
  return request<IResponseData>({
    url: '/app/v1/ctmMarketTask/queryMinus',
    method: 'post',
    data
  })
}
